package com.huatai.datacenter.controller.feignapi;

import com.huatai.common.api.R;
import com.huatai.datacenter.entity.QueryMultiple;
import com.huatai.datacenter.entity.QueryReturn;
import com.huatai.datacenter.entity.QuerySingle;
import com.huatai.datacenter.feign.TSDBQueryClient;
import com.huatai.datacenter.service.QueryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @program: ht-system
 * @description:
 * @author: songxiude
 * @create: 2023-04-25 16:22
 **/
@RestController
@AllArgsConstructor
@Api(value = "opentsdb-基础查询", tags = "opentsdb-基础查询")
public class TSDBQueryApiController implements TSDBQueryClient {

	private final QueryService queryService;

	/**
	 * 单设备基础查询
	 */
	@Override
	@PostMapping(API_PREFIX + "/single")
	@ApiOperation(value = "单设备查询", notes = "querySingle")
	public R<List<QueryReturn>> querySingle(@Valid @RequestBody QuerySingle querySingle) {
		return R.data(queryService.query(querySingle));
	}

	/**
	 * 根据时间区间进行查询
	 */
	@Override
	@PostMapping(API_PREFIX + "/multiple")
	@ApiOperation(value = "多设备查询", notes = "queryMultiple")
	public R<List<QueryReturn>> queryMultiple(@Valid @RequestBody QueryMultiple queryMultiple) {
		return R.data(queryService.query(queryMultiple));
	}

	/**
	 * 单设备基础查询
	 */
	@Override
	@PostMapping(API_PREFIX + "/singleDifference")
	@ApiOperation(value = "单设备差值计算查询", notes = "单设备差值计算查询")
	public R<List<QueryReturn>> querySingleDifference(@Valid @RequestBody QuerySingle querySingle) {
		querySingle.setDifference(true);
		return R.data(queryService.queryDifference(querySingle));
	}

}
